import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'moreFundsOrderM',
  state: {},
  effects: {
    // 银行间债券,回购新增接口
    *bondAdd({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.bondAdd, payload);
      if (response && response.code == 0) {
        callback(true);
        message.success('新增成功');
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    // 理财直融新增接口
    *finaFlockingAdd({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.finaFlockingAdd, payload);
      if (response && response.code == 0) {
        response.success = true;
        callback(response);
        message.success('新增成功');
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    // 非标新增接口
    *nonstandardAdd({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.nonstandardAdd, payload);
      if (response && response.code == 0) {
        response.success = true;
        callback(response);
        message.success('新增成功');
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取债券信息表数据
    *getBondInformationData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.getBondInformationData, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取回购信息表数据
    *getBankInformationData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.getBankInformationData, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取理财直融信息表数据
    *getFinaInformationData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.getFinaInformationData, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取非标信息表数据
    *getNonstandardInformationData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.getNonstandardInformationData, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取非标流水表数据
    *getNonstandardAccountData({ payload, callback }, { call, put }) {
      let response;
      if (payload.index == 1) {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getNonstandardAccountData, payload);
      } else {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getNonstandardAccountData2, payload);
      }
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取债券流水表数据
    *getBondAccountData({ payload, callback }, { call, put }) {
      let response;
      if (payload.index == 1) {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getBondAccountData, payload);
      } else {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getBondAccountData2, payload);
      }
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取回购流水表数据
    *getBankAccountData({ payload, callback }, { call, put }) {
      let response;
      if (payload.index == 1) {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getBankAccountData, payload);
      } else {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getBankAccountData2, payload);
      }
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    //获取理财直融流水表数据
    *getFinaAccountData({ payload, callback }, { call, put }) {
      let response;
      if (payload.index == 1) {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getFinaAccountData, payload);
      } else {
        delete payload.index;
        response = yield call(api.moreFundsOrder.getFinaAccountData2, payload);
      }
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    // 删除接口
    *deleteData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.deleteData, payload);
      if (response && response.code == 0) {
        callback(true);
        message.success('删除成功');
      } else {
        callback();
        message.error(response?.msg);
      }
    },

    // 回退接口
    *backData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.backData, payload);
      if (response && response.code == 0) {
        callback(true);
        message.success('回退成功');
      } else {
        callback();
        message.error(response?.msg);
      }
    },

    //获取行为信息表数据
    *getbehaviorData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.getbehaviorData, payload);
      if (response && response.code == 0) {
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },

    // 交收模态框
    *getSettlementModalData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.getSettlementModalData, payload);
      if (response && response.code == 0) {
        let columns = [
          {
            title: '产品组合',
            dataIndex: 'productCode',
            key: 'productCode',
            render: (val, record) => {
              return val + '-' + record.productName;
            },
          },
          {
            title: '结算金额',
            dataIndex: 'settlementAmount',
            key: 'settlementAmount',
          },
          {
            title: '是否交收',
            dataIndex: 'isSettlement',
            key: 'isSettlement',
            render: (val, record) => {
              if (val) {
                if (val == '6' || val == '11') {
                  return '否';
                } else if (val == '4' || val == '7' || val == '8') {
                  return '是';
                } else {
                  return '--';
                }
              } else {
                return '--';
              }
            },
          },
        ];
        response.data.columns = columns;
        callback(response.data);
      } else {
        callback();
        message.error(response?.msg);
      }
    },
    // 行为模态框交收接口
    *settlementModalBehaviorData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.settlementModalBehaviorData, payload);
      if (response && response.code == 0) {
        callback(true);
        message.success('交收成功');
      } else {
        callback();
        message.error(response ? response.msg : '交收失败');
      }
    },
    // 模态框交收接口
    *settlementModalData({ payload, callback }, { call, put }) {
      const response = yield call(api.moreFundsOrder.settlementModalData, payload);
      if (response && response.code == 0) {
        callback(true);
        message.success('交收成功');
      } else {
        callback();
        message.error(response ? response.msg : '交收失败');
      }
    },
    reducers: {
      save(state, { payload }) {
        return {
          ...state,
          ...payload,
        };
      },
    },
  },
};
